package com.tencent.sr.iris.basic.saas.dependency.group;

import com.tencent.sr.iris.activity.interfaces.client.task.IrisOperateBoardClient;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardStatisticsRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardThirdRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.SpecialStageListsRequest;
import com.tencent.sr.iris.activity.interfaces.response.group.AdvisorBoardResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.GroupTaskPaginationResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.operate.*;
import com.tencent.sr.iris.basic.saas.common.enums.TaskTargetEvaluationEnum;
import com.tencent.sr.iris.basic.saas.common.utils.HttpUtils;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;

@Component
@Slf4j
public class OperateTaskBoardDependency {
    @Resource
    private IrisOperateBoardClient operateBoardClient;

    public HttpResult<PaginationResponse<OperateBoardInviteResponse>> queryOperateBoardInvite(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateBoardInvite(request);
    }

    public HttpResult<PaginationResponse<OperateBoardSprintResponse>> queryOperateBoardSprint(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateBoardSprint(request);
    }

    public HttpResult<PaginationResponse<OperateBoardCommissionResponse>> queryOperateBoardCommission(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateBoardCommission(request);
    }

    public HttpResult<PaginationResponse<OperateBoardFirstOrderResponse>> queryOperateFirstOrder(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateFirstOrder(request);
    }


    public HttpResult<PaginationResponse<AdvisorBoardResponse>> queryOperateBoard(
            @Validated @RequestBody PaginationRequest<AdvisorGroupTaskRequest> request) {
        AdvisorGroupTaskRequest queryCriteria = request.getQueryCriteria();

        if (Objects.isNull(queryCriteria)) {
            queryCriteria = new AdvisorGroupTaskRequest();
            request.setQueryCriteria(queryCriteria);
        }
        List<Integer> taskTargetEvaluation = queryCriteria.getTaskTargetEvaluation();
        if (CollectionUtils.isNotEmpty(taskTargetEvaluation) &&
                taskTargetEvaluation.contains(TaskTargetEvaluationEnum.TRAINEE_LEVEL_UP.getCode())) {
            taskTargetEvaluation.add(TaskTargetEvaluationEnum.MEMBER_LEVEL_UP.getCode());
            taskTargetEvaluation.add(TaskTargetEvaluationEnum.SENIOR_LEVEL_UP.getCode());
        }
        return operateBoardClient.queryOperateBoard(request);
    }

    public HttpResult<GroupTaskPaginationResponse<OperateSecondBoardResponse>> queryOperateSecondBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateSecondBoard(request);
    }

    public HttpResult<PaginationResponse<OperateThirdBoardResponse>> queryOperateThirdBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardThirdRequest> request) {
        return operateBoardClient.queryOperateThirdBoard(request);
    }

    public OperateBoardStatisticsResponse operateBoardStatistics(
            OperateBoardStatisticsRequest request) {
        return HttpUtils.handleResult(operateBoardClient.operateBoardStatistics(request));
    }

    public List<SpecialStageListsResponse> taskGroupSpecialStageLists(
            SpecialStageListsRequest request) {
        return HttpUtils.handleResult(operateBoardClient.taskGroupSpecialStageLists(request));
    }
}
